/*
 * Copyright (c) 2011-2013 www.iflytek.com. All Rights Reserved.
 * This software for customer relationship management system, developed by zy_gczx@iflytek team.
 * Software code and design for the team, copy rights reserved.
 */

package com.iflytek.ci.main.handlers;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.iflytek.ci.cpms.dto.MilestoneCateCountDto;
import com.iflytek.framework.mapper.JsonMapper;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;

/**
 * <p>
 * 里程碑分类统计情况的JSON格式转换.
 * </p>
 *
 * @author poplar.yfyang
 * @version 1.0 2013-01-10 2:56 PM
 * @since JDK 1.5
 */
@MappedJdbcTypes(JdbcType.VARCHAR)
@MappedTypes(MilestoneCateCountDto.class)
public class MilestoneClassCountTypeHandler extends BaseTypeHandler<MilestoneCateCountDto> {
	/** JSON转换器 */
	private static final JsonMapper DEFAULT_JSON = JsonMapper.nonDefaultMapper();

	@Override
	public void setNonNullParameter(PreparedStatement ps, int i, MilestoneCateCountDto parameter, JdbcType jdbcType)
			throws SQLException {
		String json_value = DEFAULT_JSON.toJson(parameter);
		ps.setString(i, json_value);
	}

	@Override
	public MilestoneCateCountDto getNullableResult(ResultSet rs, String columnName) throws SQLException {
		String data_value = rs.getString(columnName);
		return DEFAULT_JSON.fromJson(data_value, MilestoneCateCountDto.class);
	}

	@Override
	public MilestoneCateCountDto getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
		String data_value = rs.getString(columnIndex);
		return DEFAULT_JSON.fromJson(data_value, MilestoneCateCountDto.class);
	}

	@Override
	public MilestoneCateCountDto getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
		String data_value = cs.getString(columnIndex);
		return DEFAULT_JSON.fromJson(data_value, MilestoneCateCountDto.class);
	}
}
